﻿using farming.Admins;
using Microsoft.EntityFrameworkCore;
using Volo.Abp.AuditLogging.EntityFrameworkCore;
using Volo.Abp.Data;
using Volo.Abp.DependencyInjection;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore.Modeling;

namespace farming.EntityFrameworkCore;

[ConnectionStringName("Default")]
public class farmingDbContext :
    AbpDbContext<farmingDbContext>
{
    /* Add DbSet properties for your Aggregate Roots / Entities here. */

    public DbSet<Admin> Admins { get; set; }


    public farmingDbContext(DbContextOptions<farmingDbContext> options)
        : base(options)
    {

    }

    protected override void OnModelCreating(ModelBuilder builder)
    {
        base.OnModelCreating(builder);

        /* Include modules to your migration db context */

        
        builder.ConfigureAuditLogging();

        builder.Entity<Admin>(b =>
        {
            b.ToTable(farmingConsts.DbTablePrefix + nameof(Admin), farmingConsts.DbSchema);
            b.ConfigureByConvention(); //auto configure for the base class props

            b.Property(m => m.UserName).IsRequired().HasMaxLength(50);
            b.Property(m => m.Password).IsRequired().HasMaxLength(50);
        });
    }
}
